<template>
    <div> 
    <el-form :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="名称">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="价格">
        <el-input v-model="form.price" />
      </el-form-item>
      <el-form-item label="数量">
        <el-input v-model="form.number" />
      </el-form-item>
      <el-form-item label="购物车">
        <el-select v-model="form.shop" placeholder="请选择分类">
          <el-option v-for="(item,k) in getpl" :key="k" :label="item.sname" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item>
    
        <el-button type="primary" @click="onSubmit">添加</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="getlist" style="width: 100%">
      <el-table-column prop="name" label="名称"  />
      <el-table-column prop="price" label="价格"  />
      <el-table-column prop="number" label="数量" />
      <el-table-column prop="shop" label="购物车" />
      <el-table-column label="详情">
        <template #default="scope">
          <router-link :to="`/Xq/${scope.row.id}`">详情</router-link> 
        </template>
      </el-table-column>
    </el-table>
    </div>
</template>


<script setup>
import { ref,onMounted } from "vue"
import axios from "axios"

const onSubmit=()=>{
  axios.post("http://127.0.0.1:8000/goods/go/",form.value)
  .then(res=>{
    show()
  })
}

let getpl=ref([])

const getshop=()=>{
  axios.get("http://127.0.0.1:8000/goods/shop/")
  .then(res=>{
    getpl.value=res.data
  })
}

let getlist = ref([])

let form=ref({
  name:"",
  price:"",
  number:"",
  shop:"",
})

const show=()=>{
  axios.get(" http://127.0.0.1:8000/goods/go/")
  .then(res=>{
    getlist.value=res.data
  })
}


onMounted(() => {
  show()
  getshop()
})
</script>


<style scoped> 

</style>